﻿Imports System.IO
Imports System.Web
Imports System.Text
Imports System.Xml
Imports System.Xml.Serialization
Imports MeoTom.Core.DAL

Namespace BLL
    Public Class Votes
        Public util As New Utilities.Common()

        Private _ArticleID As String
        Private _Votes As Decimal
        Private _TotalRating As Integer

        Public Property ArticleID() As String
            Get
                Return _ArticleID
            End Get
            Set(ByVal value As String)
                _ArticleID = value
            End Set
        End Property
        Public Property Votes() As Decimal
            Get
                Return _Votes
            End Get
            Set(ByVal value As Decimal)
                _Votes = value
            End Set
        End Property
        Public Property TotalRating() As Integer
            Get
                Return _TotalRating
            End Get
            Set(ByVal value As Integer)
                _TotalRating = value
            End Set
        End Property

        Public votePrv As VoteProvider

        Public Sub New()
            votePrv = New VoteProvider()
        End Sub

        Public Sub UpVote()
            Dim strOut As New StringBuilder()
            Try
                Dim reader As SqlClient.SqlDataReader = votePrv.UpVote(Me)
                If reader.Read Then
                    strOut.Append("<XML>")
                    strOut.Append("<TotalVote>").Append(reader("Votes").ToString()).Append("</TotalVote>")
                    strOut.Append("<TotalRate>").Append(reader("TotalRating").ToString()).Append("</TotalRate>")
                    strOut.Append("</XML>")

                    Dim writer As New StreamWriter(Configs.FolderSaveData & "Articles/Votes/" + reader("ArticleID").ToString() + ".xml", False, System.Text.Encoding.UTF8)
                    writer.Write(strOut.ToString())
                    writer.Flush()
                    writer.Close()
                End If
                reader.Close()
            Catch ex As Exception
            Finally
                strOut = Nothing
            End Try
        End Sub
    End Class
End Namespace